# -*- coding: utf-8 -*-

from service import Service

tuningParams = [
	'LeftRight',
	'Forward',
	'Reverse',
	'DriveTurn',
	'HomingTurn',
	'ManDrive',
	'ManTurn',
	'DockTimeout',
	]


class Settings(Service):
	""" With this service you can set all sorts of
		interesting settings
	"""
	script = "rev"
	cmd = "nav"

	def __init__(self, robot):
		""" Robot is the robot to control
		"""

		Service.__init__(self, robot)


	def _getTuningParam(self, name):
		resp = self._sendCommand({"action":16})

		s = resp.find(name)
		s = resp.find("=", s)
		ans = int(resp[s+1:resp.find(' ', s)])
		
		return ans


	def _setTuningParam(self, name, value):
		return self._sendCommand({"action":15, name:value})


	def __getattr__(self, name):
		""" Returns what you're looking for unless that
			happens to start with drive, then it returns the correct
			drive function.
		"""
		if name.find("set") == 0 and name[3:]:
			def f(value):
				return self._setTuningParam(name[3:], value)
			return f

		elif name.find("get") == 0 and name[3:]:
			def f():
				return self._getTuningParam(name[3:])
			return f
